<template>
  <div class="custom-tab-page">
    <div class="tab5-title">
      <div class="left">
        <div style="margin-right: 20px">
          <label>订单总数：</label>
          <span> {{ statisticsInfo.num }} </span>
        </div>
        <div>
          <label>订单总金额：</label>
          <span> ￥{{ statisticsInfo.parice }} </span>
        </div>
      </div>
      <!-- <el-button class="right" type="primary" @click="addFun" size="small">
        + 添加
      </el-button> -->
    </div>
    <el-table :data="tableData" border style="width: 100%; margin-top: 15px" :height="store.tableHeight - 120">
      <el-table-column prop="id" label="序号" />
      <el-table-column prop="order_no" label="订单编号" />
      <!-- <el-table-column prop="a" label="订单类型" /> -->
      <el-table-column prop="amount_real" label="订单金额" />
      <el-table-column prop="payment_datetime" label="支付日期" show-overflow-tooltip />

      <el-table-column prop="" label="订单状态">
        <template #default="{ row }">
          <el-tag v-if="row.status == 0" type="info">已取消</el-tag>
          <el-tag v-else-if="row.status == 1" type="danger"> 待支付 </el-tag>
          <el-tag v-else-if="row.status == 2" type="warning"> 支付中 </el-tag>
          <el-tag v-else-if="row.status == 3" type="success"> 已支付 </el-tag>
          <el-tag v-else-if="row.status == 4"> 已发货 </el-tag>
          <el-tag v-else-if="row.status == 6">
            已收货【过度状态，自动结算返利】
          </el-tag>
          <el-tag v-else-if="row.status == 9" type="success"> 已完成 </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="收货人">
        <template #default="{ row }">
          {{ row.send?.address_name }}
        </template>
      </el-table-column>
      <el-table-column label="收货人电话">
        <template #default="{ row }">
          {{ row.send?.address_phone }}
        </template>
      </el-table-column>
      <el-table-column prop="a" label="收货人地址" show-overflow-tooltip>
        <template #default="{ row }">
          {{ row.send?.address_province }}
          {{ row.send?.address_city }}
          {{ row.send?.address_area }}
          {{ row.send?.address_content }}
        </template>
      </el-table-column>
      <el-table-column width="120" label="操作" align="center">
        <template #default="{ row }">
          <el-button type="primary" link @click="updateOpen(row)">
            详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <div style="margin-top: 10px; display: flex; justify-content: center">
      <el-pagination :small="true" v-model:currentPage="currentPage" v-model:page-size="pageSize"
        :page-sizes="[20, 50, 100, 200]" layout="total, sizes, prev, pager, next, jumper" :total="total"
        @size-change="handleSizeChange" @current-change="handleCurrentChange" />
    </div>
  </div>
  <drawerPage ref="drawerPageRef" :remarkType="true" :priceType="true" />
</template>
<script setup>
import { listApi } from "@/plugins/api/shopping/order";
import { useCounterStore } from "@/stores/counter.js";
import drawerPage from "@/views/shopping/components/DrawerCustom.vue";
const store = useCounterStore();
const props = defineProps({
  dataInfo: {
    type: Object,
    default: {},
  },
  customInfo: {
    type: Object,
    default: {},
  },
  showItem: {
    type: Boolean,
    default: false,
  },
});

// 分页
const currentPage = ref(1);
const pageSize = ref(20);
const total = ref(0);
const handleSizeChange = (val) => {
  pageSize.value = val;
  getData();
};
const handleCurrentChange = (val) => {
  currentPage.value = val;
  getData();
};

let tableData = ref([]);

let statisticsInfo = ref({
  num: 0,
  parice: 0,
});

function getData() {
  listApi({
    page: currentPage.value,
    pageSize: pageSize.value,
    customer_id: props.dataInfo.id,
  }).then((res) => {
    tableData.value = res.list;
    statisticsInfo.value.num = res.total.customer_cnt;
    statisticsInfo.value.parice = res.total.customer_total;
    total.value = res.page.total;
  });
}
// 详情
let drawerPageRef = ref(null);
function updateOpen(row) {
  drawerPageRef.value.initFun(row);
}

function initFun() {
  tableData.value = [];
  getData();
}
defineExpose({
  initFun,
});
onMounted(() => { });
</script>

<style lang="scss" scoped>
.custom-tab-page {
  width: 100%;

  .tab5-title {
    display: flex;
    height: 46px;
    background: #fafbfc;
    box-sizing: border-box;
    padding-left: 10px;
    justify-content: space-between;

    >div {
      align-self: center;
      margin-right: 20px;

      label {
        font-size: 14px;
        font-weight: 500;
        color: #5e6c84;
      }

      span {
        font-size: 14px;
        font-weight: 500;
        color: #005ecc;
      }
    }

    .left {
      display: flex;
    }

    .right {
      align-self: center;
      margin-right: 10px;
    }
  }
}
</style>
